<?php

/**
 * Created by PhpStorm.
 * User: lawmil
 * Date: 16/10/9
 * Time: 16:50
 */
class core_phone
{

//用户名:xushengmo,密码:jgby38bj,企业ID:2906,平台:10690．

    private $username = "xushengmo";
    private $password = "jgby38bj";
    private $smsnumber = 10690;
    private $comid = 2906;
    private $url = '';

    public function __construct()
    {
        $this->url = 'http://jiekou.56dxw.com/sms/HttpInterfaceMD5.aspx?comid=COMID&username=USERNAME&userpwd=PASSWORD&handtel=MOBILE&sendcontent=CONTENT&sendtime=&smsnumber=SMSNUMBER';
        $this->url = str_replace(['COMID', 'USERNAME', 'PASSWORD', 'SMSNUMBER'], [$this->comid, $this->username, md5($this->password), $this->smsnumber], $this->url);

    }

    public function send($mobile, $code = '', $content = '')
    {
        $url = str_replace(['MOBILE', 'CONTENT'], [$mobile, $content], $this->url);
        $result = file_get_contents($url);
        $msg = $this->valid_msg($result);
        AWS_APP::model('sms')->insert_sms($mobile,$code,$msg);
        return $msg;
    }

    private function valid_msg($msg)
    {
        switch ($msg) {
            case '-1':
                return '用户名密码不正确';
            case '-2':
                return '内容不能为空';
            case '-3':
                return '验证此平台是否存在';
            case '-4':
                return '手机号不能为空';
            case '-5':
                return '客户短信数量为0';
            case '-21':
                return '代表要加签名';
            case '-22':
                return '非法手机号';
            case '-23':
                return '对某个用户名进行了屏蔽处理';
            case '1':
                return true;
            default :
                return false;


        }
    }
}